﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MeasurementTools;

namespace MainApplication
{
    public partial class MainWindow : Window
    {
        MeasurementToolsManager m_mToolsManager = MeasurementToolsManager.New();
        UserControl1 usercontrol1 = null;

        public MainWindow()
        {
            InitializeComponent();

            usercontrol1 = m_mToolsManager.CreateCircleControl("circle1");

            BitmapImage bimage = new BitmapImage();
            bimage.BeginInit();
            bimage.UriSource = new System.Uri(@"c:/1.bmp");
            bimage.EndInit();

            //image1.Source = 
            image1.Width = bimage.Width;
            image1.Height = bimage.Height;
            image1.Source = bimage;
            image1.SizeChanged += new SizeChangedEventHandler(image1_SizeChanged);
            m_mToolsManager.SetBackgroundImageSize(new Point(image1.ActualWidth, image1.ActualHeight));
			
			usercontrol1.Width = 1600;
			usercontrol1.Height = 1600;
			canvas1.Children.Add(usercontrol1);
			Canvas.SetTop(usercontrol1, 200);
			Canvas.SetLeft(usercontrol1, 200);
            usercontrol1.UpdateLayout();
        }

        void image1_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            m_mToolsManager.SetBackgroundImageSize(new Point(image1.ActualWidth, image1.ActualHeight));
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            UserControl1 uc = m_mToolsManager.CreateCircleControl("circle2");

            canvas1.Children.Add(uc);
            Canvas.SetTop(uc, 200);
            Canvas.SetLeft(uc, 200);

        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            usercontrol1.IsSelected = !usercontrol1.IsSelected;
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            usercontrol1.BrushCircleBorder = new SolidColorBrush(Colors.Red);
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            usercontrol1.BrushSelected = new SolidColorBrush(Colors.Green);
        }

        private void button5_Click(object sender, RoutedEventArgs e)
        {
            UserControl1 uc1 = m_mToolsManager.CreateCircleControl("circle2");
            UserControl1 uc2 = m_mToolsManager.CreateCircleControl("circle3");
            UserControl1 uc3 = m_mToolsManager.CreateCircleControl("circle4");
            UserControl1 uc4 = m_mToolsManager.CreateCircleControl("circle5");
            UserControl1 uc5 = m_mToolsManager.CreateCircleControl("circle6");
            UserControl1 uc6 = m_mToolsManager.CreateCircleControl("circle7");

            canvas1.Children.Add(uc1);
            canvas1.Children.Add(uc2);
            canvas1.Children.Add(uc3);
            canvas1.Children.Add(uc4);
            canvas1.Children.Add(uc5);
            canvas1.Children.Add(uc6);
            Canvas.SetTop(uc1, 200);
            Canvas.SetLeft(uc1, 200);
            Canvas.SetTop(uc2, 200);
            Canvas.SetLeft(uc2, 400);
            Canvas.SetTop(uc3, 200);
            Canvas.SetLeft(uc3, 600);
            Canvas.SetTop(uc4, 400);
            Canvas.SetLeft(uc4, 200);
            Canvas.SetTop(uc5, 400);
            Canvas.SetLeft(uc5, 400);
            Canvas.SetTop(uc6, 400);
            Canvas.SetLeft(uc6, 600);

            uc1.CircleRadius = 100;
            uc2.CircleRadius = 100;
            uc3.CircleRadius = 100;
            uc4.CircleRadius = 100;
            uc5.CircleRadius = 100;
            uc6.CircleRadius = 100;
        }

        private void button6_Click(object sender, RoutedEventArgs e)
        {
            usercontrol1.CircleRadius = 130;
        }

        private void canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement hitObject;
            hitObject = canvas1.InputHitTest(e.GetPosition(canvas1)) as FrameworkElement;

            if (hitObject.Equals(image1))
            {
                m_mToolsManager.UnselectAllControls();
            }
        }

        private void button7_Click(object sender, RoutedEventArgs e)
        {
            usercontrol1.DetailProperties = !usercontrol1.DetailProperties;
        }
    }
}
